package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsSearchHistoryMapper;
import com.qf.pojo.DtsSearchHistory;
import com.qf.service.DtsSearchHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project E-commercebackGroundManagementSystem
 * @date 2022/9/22 22:03
 */
@Service
public class DtsSearchHistoryServiceImpl implements DtsSearchHistoryService {
    @Autowired
    private DtsSearchHistoryMapper dtsSearchHistoryMapper;
    @Override
    public Page<DtsSearchHistory> selectPage(Integer page, Integer limit, String sort, String order, Integer userId, String keyword) {
        Page<DtsSearchHistory> dtsSearchHistoryPage = new Page<>(page, limit);
        QueryWrapper<DtsSearchHistory> dtsSearchHistoryQueryWrapper = new QueryWrapper<>();
        dtsSearchHistoryQueryWrapper.select("id,user_id as userId, keyword,add_time as addTime,update_time as updateTime,deleted").orderBy(!StringUtils.isEmpty(sort),"asc".equalsIgnoreCase(order),sort).eq(userId!=null,"user_id",userId).eq(!StringUtils.isEmpty(keyword),"keyword",keyword).eq("deleted",false);
        return dtsSearchHistoryMapper.selectPage(dtsSearchHistoryPage,dtsSearchHistoryQueryWrapper);
    }
}
